<template>
  <div class="only-course-list-item" @click="router.push(`/course/onlineStudy/${item.id}`)">
    <div class="course-img">
      <img :src="getFileAccessHttpUrl(item.cover)" />
    </div>
    <div class="courseBar">
      <div class="course-name wes-2">{{ item.name }}</div>
      <div class="course-desc">
        <div class="teacherName">
          <a-tag color="success" v-if="item.state==0">
            {{ item.state_dictText }}
          </a-tag>
          <a-tag color="red" v-else>
            {{ item.state_dictText }}
          </a-tag>
          <span class="studyInfo"> {{ item.learnerNumber ?? 0 }}人学习</span>
          <span class="studyInfo"> {{ item.courseStudyProcess >= 1 ? "已学完"
            : "已学" + toPercent(item.courseStudyProcess) }}</span>
        </div>
        <div class="flex_between">
          <div>
          
           <span class="studyInfo"> {{ item.taskNum ?? 0 }}个任务</span>
          </div>
          <div @click.stop="operationCollect(item.id,3)">
            <svg class="icon-third" aria-hidden="true" :style="svgIcon(item.collectEd)">
              <use xlink:href="#icon-third-shoucangguanli"></use>
            </svg>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { getFileAccessHttpUrl } from "@/utils/compUtils";
import { useRouter } from "vue-router";
import { toPercent, unitPrice } from "@/utils";
import { operation } from "@/api/course";

const props = defineProps({
  item: {
    type: Object,
    default: {}
  }
});

const router = useRouter();

async function operationCollect(id, operationType) {
  await operation(id, operationType);
  props.item.collectEd = !props.item?.collectEd;
}

function svgIcon(val) {
  if (!!val) {
    return {
      color: "red",
      fontSize: "4px"
    };
  } else {
    return {
      color: "#3f8fc3",
      fontSize: "4px"
    };
  }
}
</script>

<style scoped lang="scss">
@import "@/assets/style/course/global.scss";

.only-course-list-item {
  width: 260px;
  height: 270px;
  border-radius: 9.8px;
  opacity: 1;
  cursor: pointer;
  background: #ffffff;
  transition: all 0.4s ease;
  box-shadow: 0 1px 13px 0 #e5e5e5;
  position: relative;
  margin-bottom: 20px;

  &:hover {
    transform: translateY(-5px);
    box-shadow: 0px 1px 14px 0px #c5c5c5;

    > .white-shadow {
      opacity: 1;
    }

    > .course-img {
      > img {
        opacity: 0.8 !important;
      }
    }
  }
}

.course-img {
  text-align: center;

  > img {
    transition: all 0.4s ease;
    width: 100%;
    max-height: 156px;
    object-fit: fill;
    border-radius: 8px 8px 0 0;
  }
}

.course-name {
  font-size: 14px;
  line-height: 24px;
  color: #545C63;
  letter-spacing: 0;
  width: 100%;
  height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  -webkit-text-stroke: #979797 0.7px; /* 描边 */
}

.course-desc {
  font-size: 12px;
  font-weight: normal;
  line-height: 18px;
  letter-spacing: 0;
}

.course-price {
  font-size: 14px;
  font-weight: normal;
  line-height: 30px;
  text-align: center;
  letter-spacing: 0px;

  color: #f31947;
}

.course-type-line {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.course-type-title {
  font-size: 31px;
  font-weight: normal;
  line-height: 37px;
  letter-spacing: 0px;
  color: #333333;
}

.active {
  color: #f31947;
}

.studyInfo {
  margin-left: 20px;
  font-size: 13px;
  color: #a1a9b2;
}

.fee {
  color: #ff7a38 !important;
  font-size: 14px;
  width: 180px;
}

.courseBar {
  padding: 8px 12px 16px;
}

.teacherName {
  margin: 10px 0;
  color: #667280
}

:deep(.ant-tag) {
  margin-inline-end: 0 !important;
}

.flex_between {
  display: flex;
  justify-content: space-between
}

</style>
